package cn.liu.hrm.web.controller;

import cn.liu.hrm.util.AjaxResult;
import cn.liu.hrm.utils.FastDfsApiOpr;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

//文件上传
@RestController
public class FastfdsController {

    //上传方法
    @RequestMapping(value = "/fastdfs/upload",method = RequestMethod.POST)
    public AjaxResult upload(MultipartFile file) throws IOException {

        //调用fastdfs工具上传到fastdfs服务端
        String extName =  FilenameUtils.getExtension(file.getOriginalFilename()); //获取扩展名
        String filePathInFastdfs = FastDfsApiOpr.upload(file.getBytes(), extName);
        return AjaxResult.me().setResultObj(filePathInFastdfs);
    }
    //下载方法

    //删除方法
}
